<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" destroy-on-close @closed="$emit('closed')" align-center fullscreen>
        <el-container>
            <el-main>
                <el-form :model="form" :rules="rules" :disabled="mode == 'show'" ref="dialogForm" label-width="110px" label-position="right" style="height:750px;overflow:auto">
                    <el-row :gutter="1">
						<el-col :span="6">
							<el-form-item label="承制人">
								<el-input v-model="info.apply_name" placeholder="承制人" readonly />
							</el-form-item>
						</el-col>
                        <el-col :span="6">
                            <el-form-item label="应付">
                                <el-input v-model="info.total_amount" placeholder="应付" readonly/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="实付">
                                <el-input v-model="info.pay_amount" placeholder="实付" readonly />
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="1">
                        <el-col :span="6">
                            <el-form-item label="补扣">
                                <el-input v-model="info.deduction_amount" placeholder="补扣" readonly />
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="备注">
                                <el-input v-model="info.remark" readonly />
                            </el-form-item>
                        </el-col>
                    </el-row>
					<el-row :gutter="1">
						<el-col :span="24">
							<el-form-item label="合同信息">
								<sc-table style="width: 100%" ref="table" :data="info.contract_data" height="300" border hideDo hidePagination highlight-current-row @current-change="handleCurrentChange">
									<el-table-column label="批次号" prop="batch_number" align="center"></el-table-column>
									<el-table-column label="发织合同号" prop="contract_no" align="center"></el-table-column>
									<el-table-column label="工序名" prop="process_title" align="center"></el-table-column>
									<el-table-column label="发织数" prop="weaving_num" align="center"></el-table-column>
									<el-table-column label="收货数" prop="take_num" align="center"></el-table-column>
									<el-table-column label="返工数" prop="rework_num" align="center"></el-table-column>
									<el-table-column label="待收" prop="pending_num" align="center"></el-table-column>
									<el-table-column label="收货重" prop="take_weight" align="center"></el-table-column>
									<el-table-column label="单价" prop="price" align="center"></el-table-column>
									<el-table-column label="单位" prop="unit_name" align="center"></el-table-column>
									<el-table-column label="应付" prop="total_amount" align="center"></el-table-column>
									<el-table-column label="实付" prop="pay_amount" align="center"></el-table-column>
									<el-table-column label="货期" prop="delivery_time" align="center"></el-table-column>
									<el-table-column label="末次收货" prop="last_take_date" align="center"></el-table-column>
									<el-table-column label="补/扣" prop="deduction_amount" align="center"></el-table-column>
									<el-table-column label="备注" prop="remark" align="center" ></el-table-column>
								</sc-table>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row :gutter="1">
						<el-col :span="24">
							<el-form-item label="毛种信息">
								<sc-table style="width: 100%" ref="table" :data="info.material_data" height="300" border hideDo hidePagination showSummary>
									<el-table-column label="缸号" prop="batch_number" align="center"></el-table-column>
									<el-table-column label="毛种" prop="material_name" align="center" ></el-table-column>
									<el-table-column label="损耗" prop="loss_ratio" align="center" ></el-table-column>
									<el-table-column label="预发重" prop="pre_weight" align="center"></el-table-column>
									<el-table-column label="实发重" prop="actual_weight" align="center"></el-table-column>
									<el-table-column label="收货重" prop="take_weight" align="center"></el-table-column>
									<el-table-column label="退毛重" prop="return_weight" align="center"></el-table-column>
									<el-table-column label="计毛方式" prop="way_name" align="center"></el-table-column>
									<el-table-column label="欠毛重" prop="owe_weight" align="center"></el-table-column>
									<el-table-column label="单价" prop="price" align="center"></el-table-column>
									<el-table-column label="补/扣" prop="deduction_amount" align="center"></el-table-column>
									<el-table-column label="备注" prop="remark" align="center"></el-table-column>
								</sc-table>
							</el-form-item>
						</el-col>
					</el-row>
                </el-form>
            </el-main>
        </el-container>
	</el-dialog>
</template>

<script>
	export default {
		emits: ['success', 'closed'],
		data() {
			return {
				mode: "add",
				titleMap: {
					add: '结算明细',
					edit: '结算明细',
					show: '查看'
				},
				visible: false,
				isSaveing: false,
                grade:"潜力",
                info:{
                    remark:"",
                    supplier_id:"",
                    contract_data:[],
                    material_data:[],
                    total_amount:"",
                    pay_amount:"",
                    deduction_amount:"",
	                apply_name:''
                },
                addTemplate:{},
                applyList:[],
                selection: [],
				//表单数据
				form: {},
			}
		},
		mounted() {
            this.getApply()
        },
		methods: {
			//显示
			open(mode='add'){
				this.mode = mode;
				this.visible = true;
				return this
			},
			//表单注入数据
			async setData(data){
				this.info.apply_name = data.apply_name
				console.log(data,this.info.apply_name)
                var res = await this.$API.produce.waitSettled.detail.get({statement_no:data.statement_no});
                let array = []
                res.data.contractDetail.map(item=>{
                    array.push({
                        batch_number:item.batch_number,
                        contract_no:item.contract_no,
                        process_title:item.process_title,
                        price:item.price,
                        unit_name:item.unit_name,
                        weaving_num:item.weaving_num,
                        take_num:item.take_num,
                        pending_num:item.pending_num,
                        rework_num:item.rework_num,
                        total_amount:item.total_amount,
                        pay_amount:item.pay_amount,
                        take_weight:item.take_weight,
                        delivery_time:item.delivery_time,
                        last_take_date:item.last_take_date,
                        remark:item.remark,
                        deduction_amount:item.deduction_amount,
                        materialData:item.materialData
                    })
                    this.info.contract_data = array
                })
                this.info.total_amount = res.data.total_amount
                this.info.pay_amount = res.data.goods_amount
                this.info.deduction_amount = res.data.deduction_amount
                this.info.supplier_id = res.data.supplier_id
                this.info.remark = res.data.remark
                this.info.material_data = res.data.materialDetail
			},
            async getApply(){
                var res = await this.$API.all.Apply.get();
                this.applyList = res.data;
            },
            handleCurrentChange(selection){
                this.info.material_data = selection.materialData
            },
		}
	}
</script>

<style lang="scss"></style>
